﻿Imports System.ComponentModel.Composition
Imports System.Text

<ExportCompent(GetType(IInfoProccessor), "Internal", "6e8df6c3-c25f-4b84-9fe5-ea4a8c2cece1", "1.0.0.1")>
Public Class InternalProccessor
    Inherits InfoProccesssorBase

    Private settingWindow As SettingsWindow

    Private rawString As String

    Public Overrides Function GetAvailability() As Boolean
        Return True
    End Function

    Public Overloads Overrides Function ProccessInfo(infos As System.Collections.Generic.Dictionary(Of String, String)) As String
        Dim result As StringBuilder = New StringBuilder(rawString)
        For Each item In infos
            result.Replace(String.Format("<{0}>", item.Key), item.Value)
        Next
        Return result.ToString
    End Function

    Public Overloads Overrides Function ProccessInfo(infos As System.Collections.Specialized.NameValueCollection) As String
        Dim result As StringBuilder = New StringBuilder(rawString)
        For Each item In infos
            result.Replace(String.Format("<{0}>", item.Key), item.Value)
        Next
        Return result.ToString
    End Function

    Public Overrides Sub ShowSetting()
        settingWindow = New SettingsWindow()
        settingWindow.SettingText = rawString
        settingWindow.ShowDialog()
        rawString = settingWindow.SettingText
    End Sub

    Public Overrides Sub ShutDown()
        My.Settings.RawString = rawString
        My.Settings.Save()
    End Sub

    Public Overrides Sub StartUp()
        rawString = My.Settings.RawString
    End Sub
End Class
